package Demo1;

import java.util.Scanner;

//书本操作类
public class BookService {
    //
    private Book[] books;
    public BookService(Book [] books){
        this.books = books;
    }

    //遍历所有书籍然后打印
    public void printAllBook() {
        for(int i = 0; i < books.length; i++){
            Book book = books[i];
            System.out.println(book.getName() + "\t" + book.getActor());
        }
    }

    //根据ID查找书籍
    public void SeachBookID() {
        System.out.println("请输入要查找的书籍ID：");
        Scanner sc = new Scanner(System.in);
        int id = sc.nextInt();

        for(int i = 0; i < books.length; i++){
            Book book = books[i];
            if(book.getID() == id){
                System.out.println( "书名：" + book.getName() + "\t" + "主角：" + book.getActor());
                return;
            }
        }
        System.out.println("没有找到");
    }
}
